<template>
  <div class="container">
    <index-head></index-head>
    <div class="message_table">
      <el-table :data="tableData" style="width: 100%" :show-header="false">
        <el-table-column prop="date">
          <template slot-scope="scope">
            <img src="../assets/image/login_point.png"> <span>{{ scope.row.date}}</span>
            系统消息
          </template>
        </el-table-column>
        <el-table-column prop="msgContent" width="940">
          <template slot-scope="scope">
            <div @click="handleCheck(scope.row)">
              {{ scope.row.msgContent}}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="readFlag">
          <template slot-scope="scope">
            <span v-if="scope.row.readFlag==='1'" style="color:#f15a24">已读</span>
            <span v-else style="color: #00ffff">未读</span>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page"
                     :page-sizes="[20, 40, 60, 80]" :page-size="limit" layout="total, sizes, prev, pager, next, jumper"
                     :total="total">
      </el-pagination>
      <!--      <turn-page></turn-page>-->
    </div>
    <com-foot></com-foot>
  </div>
</template>

<script>
  import _ from 'lodash';
  import indexHead from '../components/head'
  // import turnPage from '../components/turnPage'
  import comFoot from '../components/comfoot'
  export default {
    data() {
      return {
        tableData: [],
        page: 1,
        limit: 20,
        total: 0,
        token: localStorage.getItem('TOKEN_KEY'),
      }

    },
    components: {
      comFoot,
      indexHead,
      // turnPage
    },

    methods: {
      handleCheck(row) {
        let callBack = ()=>{
          let {indexCode, regionCode, timeCode, templateName} = row
          localStorage.setItem('macroCodes', JSON.stringify({indexCode, regionCode, timeCode}))
          this.$router.push({path: '/macro4', query: {tablename: templateName, pageType: 'changeParam'}})
        }
        if(row.readFlag==='1'){
          callBack()
          return
        }
        const loading = this.$loading({
          lock: true,
          text: '正在加载中...',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        this.$axios
          .request({
            url: `5200/sysannouncement/setflag/${row.id}`,
            method: "get",
            params: {
              access_token: this.token,
            },
          })
          .then(res => {
            if (String(res.data.resp_code) === '1') {  // 失败
              this.$message.error(res.data.resp_msg);
              return
            }
            callBack()
          })
          .finally(() => {
          loading.close();
        })
      },
      handleSizeChange(val) {
        this.limit = val
        this.getList()
      },
      handleCurrentChange(val) {
        this.page = val
        this.getList()
      },
      getList() {
        this.$axios
          .request({
            url: "5200/sysannouncement/getUpdateDataInfo",
            method: "get",
            params: {
              access_token: this.token,
              titile: this.title,
              page: this.page,
              limit: this.limit,
            },
          })
          .then(res => {
            this.tableData = Object.assign([], _.get(res, 'data.data', []))
            this.total = _.get(res, 'data.count', 0)
          })
      },
    },
    created() {
      this.getList()
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
  .message_table {
    width: 1330px;
    margin: 30px auto 40px;
    text-align: center;
  }


  .message_table .el-table__row .el-table_1_column_1 {
    color: #fbb03b;
  }

  .message_table .el-table__row .el-table_1_column_3 {
    color: #00ffff;
  }

  .message_table .cell img, .message_table .cell span {
    vertical-align: middle;
  }
</style>
<style scoped>
  .footer{
    position: fixed;
  }
</style>